#include <QApplication>
#include <QWidget>
#include <QGridLayout>
#include <QString>
#include <QColor>
#include <QLabel>
#include <QPixmap>
#include <QIcon>
#include <QCloseEvent>
#include <QPalette>

#include <iostream>
#include <sstream>

#include "refwin.h"
#include "globalconstants.h"
#include "see.h"


qRefWin::qRefWin(QWidget *parent)
{
  //setMaximumSize(1,1);
  setWindowTitle("Referencias");
  setWindowIcon(QIcon(iconRef));
  QGridLayout *refLayout = new QGridLayout;
  QLabel *labelToT=new QLabel("Time Over Threshold");
  
  QLabel *picToT=new QLabel();
  picToT->setPixmap(QIcon(iconToT).pixmap(50));
  
  QPixmap *pixToT=new QPixmap(40,30);
  pixToT->fill(colorToT);
  QLabel *colToT=new QLabel();
  colToT->setPixmap(*pixToT);
  
  refLayout->addWidget(colToT, 0, 0);
  refLayout->addWidget(picToT, 0, 1);
  refLayout->addWidget(labelToT, 0, 2);
  
  QLabel *labelThr2=new QLabel("Threshold Level 2");
  
  QLabel *picThr2=new QLabel();
  picThr2->setPixmap(QIcon(iconThr2).pixmap(50));
  
  QPixmap *pixThr2=new QPixmap(40,30);
  pixThr2->fill(colorThr2);
  QLabel *colThr2=new QLabel();
  colThr2->setPixmap(*pixThr2);
  
  refLayout->addWidget(colThr2, 1, 0);
  refLayout->addWidget(picThr2, 1, 1);
  refLayout->addWidget(labelThr2, 1, 2);
  
  
  QLabel *labelThr1=new QLabel("Threshold Level 1");
  
  QLabel *picThr1=new QLabel();
  picThr1->setPixmap(QIcon(iconThr1).pixmap(50));
  
  QPixmap *pixThr1=new QPixmap(40,30);
  pixThr1->fill(colorThr1);
  QLabel *colThr1=new QLabel();
  colThr1->setPixmap(*pixThr1);
  
  refLayout->addWidget(colThr1, 2, 0);
  refLayout->addWidget(picThr1, 2, 1);
  refLayout->addWidget(labelThr1, 2, 2);
  
  setLayout(refLayout);
}

void qRefWin::closeEvent(QCloseEvent *event)
{
  emit openWindow(false);
}

qWaitWin::qWaitWin(QWidget *parent)
{
  setMaximumSize(300,200);
  setMinimumSize(300,200);
  setGeometry (300,300, 300, 200 );
  label=new QLabel("Hola amigos");
  //label->setText("Hola amigos");
  QGridLayout *layout = new QGridLayout;
  layout->addWidget(label,0,0);
  setLayout(layout);
}

void qWaitWin::setText(QString texto)
{
  //label->setText(texto);
}

qInfo::qInfo(QWidget *parent)
{
  //setMaximumSize(1,1);
  setWindowTitle("Info");
  setWindowIcon(QIcon(iconInfo));
  setWindowFlags(Qt::WindowStaysOnTopHint);
  label=new QLabel();
  label->setFrameStyle(QFrame::Box);
  QPalette pal = label->palette();
  pal.setColor(label->backgroundRole(), Qt::white);
  //label->setAutoFillBackground( true );
  label->setPalette(pal);
  label->setMargin (5);
  QGridLayout *layout = new QGridLayout;
  layout->addWidget(label,0,0);
  setLayout(layout);
}

qInfo::qInfo(tCandidate *sInfo,QWidget *parent)
{
  //setMaximumSize(1,1);
  setWindowTitle("Info");
  setWindowIcon(QIcon(iconInfo));
  setWindowFlags(Qt::WindowStaysOnTopHint);
  label=new QLabel();
  label->setFrameStyle(QFrame::Box);
  QPalette pal = label->palette();
  pal.setColor(label->backgroundRole(), Qt::white);
  //label->setAutoFillBackground( true );
  label->setPalette(pal);
  label->setMargin (5);
  QGridLayout *layout = new QGridLayout;
  layout->addWidget(label,0,0);
  setLayout(layout);
  setInfo(sInfo);
}

void qInfo::closeEvent(QCloseEvent *event)
{
  emit openWindow(false);
}

void qInfo::setInfo(tCandidate *sInfo)
{
  std::ostringstream s(std::ostringstream::out);
  
  s <<"Tank ID: "<<sInfo->sId<<endl
      <<"Total VEM: "<<sInfo->totalVem<<endl
      <<"Risetime: "<<sInfo->riseTime<<endl
      <<"Falltime: "<<sInfo->fallTime<<endl;
  label->setText(s.str().c_str());
}
